import 'package:flutter_frame/app/components/custom_app_bar.dart';
import 'package:flutter_frame/app/components/toast_widget.dart';
import 'package:flutter_frame/app/core/core.dart';
import 'package:flutter_frame/app/core/values/gaps.dart';
import 'package:flutter_frame/app/modules/auth/login/controller.dart';
import 'package:flutter_frame/global.dart';

/// @Author: leijingxing
/// @Date: 2023-03-17
/// @LastEditTime: 2023-03-17 13:58
/// @LastEditors: leijingxing
/// @Description: 登录页

class LoginPage extends StatelessWidget {
  LoginPage({Key? key}) : super(key: key);

  final controller = Get.put(LoginController());
  final states = Get.find<LoginController>().states;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
          resizeToAvoidBottomInset: false,
          appBar: CustomAppBar(
          ),
          body: Center(
              child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
               Text(Global.packageInfo.appName),
              AppGaps.hGap150,
              TextField(
                controller: controller.textEditingControllerUserName,
                decoration: const InputDecoration(
                  hintText: '用户名',
                ),
              ),
              TextField(
                controller: controller.textEditingControllerPassword,
                decoration: const InputDecoration(
                  hintText: '密码',
                ),
              ),
              ElevatedButton(
                  onPressed: controller.loginDo, child:  Text('登录'))
            ],
          )),
          floatingActionButton: FloatingActionButton(
            onPressed: controller.goHome,
          ),
        ),
        onWillPop: () async {
          if (controller.isAndroid) {
            if (controller.lastPressedAt == null ||
                DateTime.now().difference(controller.lastPressedAt!) >
                    const Duration(seconds: 1)) {
              controller.lastPressedAt = DateTime.now();
              AppToast.showWarning('再次点击，立即退出App');
              // Fluttertoast.showToast(
              //   msg: '再次点击，立即退出App',
              // );
              return false;
            } else {
              // exit(-1);
            }
          }
          return true;
        });
  }
}
